package edu.ccut.saturn.studio.logic.model.saturn;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.graphics.Image;
import org.w3c.dom.Node;

import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.dialog.informationdialog.SaturnInformationDialog;
import edu.ccut.saturn.studio.export.createhtml.Parameters;
import edu.ccut.saturn.studio.logic.figure.SaturnFigure;
import edu.ccut.saturn.studio.logic.model.Shape;

public class SaturnInformationNode extends Shape {

	private static final long serialVersionUID = 578646584189638719L;

	public static final String KEY_NODE_INFORMATION = "information";
	
	public static final String KEY_NODENAME_INFORMATION = Messages.getString("SaturnInformationNode.InformationName"); //$NON-NLS-1$

	public static final String KEY_PROPERTY_INFORMATION_NODE_KEY = "_property_key";

	public static final String KEY_PROPERTY_INFORMATION_NODE_SYMBOLICNAME = "_property_bundle-symbolicname";

	public static final String KEY_PROPERTY_INFORMATION_NODE_NAME = "_property_name";

	public static final String KEY_PROPERTY_INFORMATION_NODE_DESCRITPION = "_property_description";

	public static final String SHOW_INFORMATION_NODE_KEY = "key";

	public static final String SHOW_INFORMATION_NODE_NAME = "name";

	public static final String SHOW_INFORMATION_NODE_DESCRITPION = "description";
	
	public static final String SHOW_INFORMATION_NODE_LOADSTART = "loadstart";

	private static int number = 1;

	private String type = "";

	private Image image = Activator.getImage(Images.INFORMATION_ICON);

	public SaturnInformationNode() {
		super.setName(KEY_NODENAME_INFORMATION + number++);
	}

	@Override
	public Image getIcon() {
		return image;
	}

	@Override
	public IFigure getFigure() {
		SaturnFigure saturnFigure = new SaturnFigure();
		saturnFigure.setIcon(image);
		saturnFigure.setName(super.getName());

		return saturnFigure;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
		firePropertyChange(PROPERTERY_CHANGS, null, type);
	}

	@Override
	public Node doRefresh() {
		Node root = super.getRoot();

		Node informationNode = SaturnW3CUtil.createChildNode(root,
				KEY_NODE_INFORMATION, null);

		SaturnW3CUtil.createChildNode(informationNode,
				SHOW_INFORMATION_NODE_KEY, super.getKey());

		SaturnW3CUtil.createChildNode(informationNode,
				SHOW_INFORMATION_NODE_NAME, super.getName());
		
		SaturnW3CUtil.createChildNode(informationNode,
				SHOW_INFORMATION_NODE_LOADSTART, super.getSelection());

		return informationNode;
	}

	public Dialog getDialog() {
		SaturnInformationDialog dialog = new SaturnInformationDialog(super
				.getShell(), this);
		super.reorder(this);
		return dialog;
	}

	@Override
	public Shape cloneShape(Point mousePoint, Shape shape) {
		return null;
	}

	@Override
	protected void setImage(Image image) {
		this.image = image;
	}

	@Override
	public Parameters createNodeHtml(String filePath, String[] tempnames) {
		return null;
	}
}
